﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Globalization;
using System.Drawing;
using System.ComponentModel;

namespace KELT.Controls.Page
{
    
    public class PageObjectWidthConverter : IValueConverter
    {
        public object Convert(object o, Type type, object parameter, CultureInfo culture)
        {
            return ((double)o) - 40;
        }

        public object ConvertBack(object o,Type type, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }
    
    /*
    public class PageObjectWidthConverter : TypeConverter
    {
        // Overrides the CanConvertFrom method of TypeConverter.
        // The ITypeDescriptorContext interface provides the context for the
        // conversion. Typically, this interface is used at design time to 
        // provide information about the design-time container.
        public override bool CanConvertFrom(ITypeDescriptorContext context,
           Type sourceType)
        {

            if (sourceType == typeof(double) || sourceType == typeof(int))
            {
                return true;
            }
            return base.CanConvertFrom(context, sourceType);
        }
        // Overrides the ConvertFrom method of TypeConverter.
        public override object ConvertFrom(ITypeDescriptorContext context,
           CultureInfo culture, object value)
        {
            if (value is double)
            {
                double v = ((double)value) - 20;
                return v;
            }else if(value is int)
            {
                int v = ((int)value) - 20;
                return v;
            }
            return base.ConvertFrom(context, culture, value);
        }
        // Overrides the ConvertTo method of TypeConverter.
        public override object ConvertTo(ITypeDescriptorContext context,
           CultureInfo culture, object value, Type destinationType)
        {
            if (value is double)
            {
                double v = ((double)value) - 20;
                return v;
            }
            else if (value is int)
            {
                int v = ((int)value) - 20;
                return v;
            }
            return base.ConvertTo(context, culture, value, destinationType);
        }
    }
     * */
}
